<?php

namespace App\Kuafu\CustomerCoupon\Model;

use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Shop\Model\Shop;
use Illuminate\Database\Eloquent\Relations\HasOne;

class CustomerCouponShopMappingModel extends BaseModel
{
    use KfSoftDeletes;

    protected $connection = 'mysql';
    protected $table      = 'customer_coupon_shop_mappings';
    protected $primaryKey = 'id';
    protected $fillable   = ['customerCouponId','shopId','createdAt'];

    protected $hidden = [
        'updatedAt',
        'isDeleted'
    ];

    public static function addData(array $data)
    {
        return self::query()->insert($data);
    }

    public static function setStatus(int $id, int $status): int
    {
        return self::query()->where('id', $id)->update(['status' => $status]);
    }

    /**
     * @return HasOne
     */
    public function shopRel(): HasOne
    {
        return $this->hasOne(Shop::class, "id", "shopId");
    }
}
